﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RelocateLocationToTcpf.CApRelocateLocationToTcpfEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;


namespace DnProcessSimulateCommands.RelocateLocationToTcpf;

public class CApRelocateLocationToTcpfEnabler : ITxCommandEnabler
{
  public bool Enable
  {
    get
    {
      bool enable = false;
      if (TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded() && TxApplication.ActiveSelection.TotalCount == 1)
      {
        TxObjectList items = TxApplication.ActiveSelection.GetItems();
        if (((Collection<ITxObject>) items).Count == 1)
        {
          ITxObject itxObject = ((Collection<ITxObject>) items)[0];
          if (itxObject is ITxRoboticLocationOperation)
            enable = TxRobot.op_Inequality(CApRelocateLocationToTcpfEnabler.GetRobot(itxObject as ITxRoboticLocationOperation), (ITxObject) null);
          else if (itxObject is ITxRoboticOperation)
            enable = TxRobot.op_Inequality(CApRelocateLocationToTcpfEnabler.GetRobot(itxObject as ITxRoboticOperation), (ITxObject) null);
          if (enable && CApRelocateLocationToTcpfEnabler.ShouldCheckLocationForCanBeModified() && itxObject != null)
            enable = itxObject.CanBeModified;
        }
      }
      return enable;
    }
  }

  private static TxRobot GetRobot(ITxRoboticOperation operation)
  {
    TxRobot robot = (TxRobot) null;
    if (operation != null)
    {
      if (operation is ITxRoboticOrderedCompoundOperation)
        robot = (operation as ITxRoboticOrderedCompoundOperation).Robot as TxRobot;
      else if (((ITxObject) operation).Collection != null && ((ITxObject) operation).Collection is ITxRoboticOrderedCompoundOperation)
        robot = (((ITxObject) operation).Collection as ITxRoboticOrderedCompoundOperation).Robot as TxRobot;
    }
    return robot;
  }

  internal static TxRobot GetRobot(ITxRoboticLocationOperation location)
  {
    TxRobot robot = (TxRobot) null;
    if (location != null && location.ParentRoboticOperation != null)
      robot = location.ParentRoboticOperation.Robot as TxRobot;
    return robot;
  }

  public static bool ShouldCheckLocationForCanBeModified() => TxTcUtilities.IsTcAnyPlatform;
}
